import bpmnFromsApi from '@/api/bpmn/bpmnFromsApi.js';
import collectionApi from '@/api/documents/collectionApi.js';

import DragBox from '@/views/components/yu-dragLayouter/dragBox.vue';
import DragItem from '@/views/components/yu-dragLayouter/dragItem.vue';
import { apiOnlinePrint } from '@/api/documents/onlineApi.js'; // 文件预览 以及文件下载
import { debounce, throttle } from '@/utils/yuUtils.js';
import printJS from 'print-js';
import { decryptData } from '@/utils/encryp.js';
// 企业 团队 个人的全局参数和方法
export default (configs) => {
  const requstApi = configs.requstApi;
  const pageType = configs.pageType; //enterprise:企业,team:团队,self:个人
  return {
    components: {
      DragBox,
      DragItem
    },
    data: () => ({
      // pageType: "enterprise",
      isTableHeaderBtn: false, //是否隐藏表格头
      /*复制and移动----------------*/
      copyAndMoveArray: [], //保存要复制移动的数组
      copyAndMoveType: '', //保存当前要复制移动类别
      /*------------------------*/
      /**排序 */
      treeRequestParams: {
        // sortAsc: pageType == "team" ? "" : "sort",
        // sortDesc: pageType == "team" ? "" : "type,create_time",
        //企业是下面的
        // sort: "sort Asc,type Desc,create_time Desc"
        sort: ['sort Asc', 'type Desc', 'create_time Desc']
      },
      tableHeight: 0,
      // 拖动
      resizeConf: {
        width: 270, // 初始宽度
        widthRange: [200, 1500] // 宽度范围
      },
      /**搜索----start */
      searchInfoObj: {}, //保存搜索出来单击了的数据,用于高亮这一行
      searchTableDataClone: [],
      /**搜索----end */

      /**表格分页---start */
      tableRequestParams: {
        page: 0,
        size: 40,
        parentId: 0,
        pageCount: 1
      },
      tableLoading: false,
      isTableTopMoreText: false,
      toploadMorePage: 0,
      /**表格分页---end */
      /**保存摆渡请求参数---start  */
      ferryRequestParams: {
        fileIds: [],
        userIds: []
      }
      /**保存摆渡请求参数---end  */
    }),
    // 监听表格滚动
    // directives: {
    //   loadmore: {
    //     bind(el, binding, vnode) {
    //       const selectWrap = el.querySelector(".el-table__body-wrapper");
    //       selectWrap.addEventListener("scroll", function () {
    //         // console.log(this.scrollTop);
    //         const scrollDistance = this.scrollHeight - this.scrollTop - this.clientHeight;
    //         // 从 Vue 实例中获取 page 的值
    //         const page = vnode.context.$data.tableRequestParams.page;
    //         const isTableTopMoreText = vnode.context.$data.isTableTopMoreText;
    //         // console.log(this.scrollTop <= 0 , isTableTopMoreText);
    //         if (this.scrollTop <= 0 && vnode.context.$data.toploadMorePage != 0) {
    //           vnode.context.$data.isTableTopMoreText = true;
    //         } else {
    //           vnode.context.$data.isTableTopMoreText = false;
    //         }
    //         if (page > 0 && scrollDistance <= 0.9) {
    //           binding.value(); //执行在使用时绑定的函数，在这里即loadMorePerson方法
    //         }
    //       });
    //     }
    //   }
    // },
    directives: {
      loadmore: {
        bind(el, binding, vnode) {
          const selectWrap = el.querySelector('.el-table__body-wrapper');

          // 使用防抖函数来包装滚动事件处理函数
          const debouncedScrollHandler = debounce(function () {
            const scrollDistance = this.scrollHeight - this.scrollTop - this.clientHeight;
            const page = vnode.context.$data.tableRequestParams.page;
            const isTableTopMoreText = vnode.context.$data.isTableTopMoreText;

            if (this.scrollTop <= 0 && vnode.context.$data.toploadMorePage != 0) {
              vnode.context.$data.isTableTopMoreText = true;
            } else {
              vnode.context.$data.isTableTopMoreText = false;
            }

            if (page > 0 && scrollDistance <= 0.9) {
              binding.value(); // 执行在使用时绑定的函数
            }
          }, 300); // 调整延迟时间以适应你的需求

          // 保存监听器引用
          selectWrap._scrollHandler = debouncedScrollHandler;
          selectWrap.addEventListener('scroll', selectWrap._scrollHandler);
        }
      }
    },
    created() {
      this.tableHeight = window.innerHeight - 98;

      window.onresize = () => {
        //浏览器窗口变动的时候
        this.tableHeight = window.innerHeight - 98;
      };
    },
    mounted() {},

    methods: {
      // 右键菜单事件
      async onContextmenu(event) {
        // console.log(this.tableRowArray, "this.tableRowArray");
        // this.pageType = pageType//用于判断是哪个页面
        // if (this.copyAndMoveArray.length > 0) {
        //    this.$contextmenu({
        //       items: [
        //          {
        //             icon: "el-icon-scissors",
        //             label: "粘贴",
        //             hidden: this.copyAndMoveArray.length > 0 && pageType != 'enterprise' ? false : true,
        //             onClick: () => { this.menuStick() }
        //          }
        //       ],
        //       event,
        //       //x: event.clientX,
        //       //y: event.clientY,
        //       customClass: "custom-class",
        //       zIndex: 9999,
        //       minWidth: 160
        //    });
        // } else
        let myFIleRoleList = [];
        if (pageType == 'enterprise') {
          this.$store.dispatch('getEnteroriseFileRole', {
            params: this.tableRowArray[0]
          });
          myFIleRoleList = this.$store.state.enterpriseRole.enterpriseMyRoleList;
          // console.log(myFIleRoleList,'myFIleRoleList123');
        }
        // if (pageType == "team") {
        //   let paramsString = {
        //     teamId: this.teamId,
        //     treeNodeIds: [this.tableRowArray[0].id],
        //     userId: this.$store.state.user.user.id
        //   };
        //   let res = await this.$store.dispatch("getUserTeamFileRoleApi", {
        //     params: paramsString
        //   });
        //   myFIleRoleList = JSON.parse(res.obj[0].params);
        // }
        // console.log( this.judgePermission('jurisdiction', myFIleRoleList),'222222222');

        if (pageType == 'team') {
          let paramsString = {
            teamId: this.teamId,
            treeNodeIds: [this.tableRowArray[0].id],
            userId: this.$store.state.user.user.id
          };

          let res = await this.$store.dispatch('getUserTeamFileRoleApi', {
            params: paramsString
          });

          // let myFIleRoleList = [];

          // Iterate over the returned data and merge the permissions
          if (res && res.obj && res.obj.length > 0) {
            res.obj.forEach((roleData) => {
              if (roleData.params) {
                try {
                  // Parse the params and merge them into myFIleRoleList
                  let parsedParams = JSON.parse(roleData.params);
                  myFIleRoleList = myFIleRoleList.concat(parsedParams);
                } catch (e) {
                  console.error('Error parsing params:', e);
                }
              }
            });

            // Optionally, remove duplicates if needed
            myFIleRoleList = Array.from(new Set(myFIleRoleList.map(JSON.stringify))).map(JSON.parse);
          }

          // console.log(myFIleRoleList, "Combined Permissions List");
        }

        if (this.tableRowArray.length == 0) {
          return false;
        } else {
          this.$contextmenu({
            items: [
              {
                icon: 'el-icon-view',
                label: this.tableRowArray[0].type == 'folder' ? this.$t('teamDoc.rightBtnList.open') : this.$t('teamDoc.rightBtnList.preview'),
                disabled: this.judgePermission('check', myFIleRoleList),
                onClick: () => {
                  this.menuPreview();
                }
              },
              {
                icon: 'el-icon-edit',
                label: this.$t('teamDoc.rightBtnList.edit'),
                hidden: this.tableRowArray[0].type == 'folder',
                disabled: this.judgePermission('update', myFIleRoleList),
                onClick: () => {
                  this.menuOnlineEdit();
                }
              },
              {
                icon: 'el-icon-printer',
                label: this.$t('teamDoc.rightBtnList.print'),
                hidden:
                  this.tableRowArray[0].type == 'folder' ||
                  !(
                    this.tableRowArray[0].suffix == 'doc' ||
                    this.tableRowArray[0].suffix == 'docx' ||
                    this.tableRowArray[0].suffix == 'xls' ||
                    this.tableRowArray[0].suffix == 'xlsx' ||
                    this.tableRowArray[0].suffix == 'pdf'
                  ),
                disabled: this.judgePermission('print', myFIleRoleList),
                onClick: () => {
                  this.menuPrintClick(this.tableRowArray[0]);
                }
              },
              {
                icon: 'el-icon-download',
                label: this.$t('teamDoc.rightBtnList.download'),
                divided: true, //是否显示分割线
                disabled: this.judgePermission('download', myFIleRoleList),
                onClick: () => {
                  this.menuDownload();
                }
              },
              {
                icon: 'el-icon-top',
                label: this.tableRowArray[0].sort == -1 ? this.$t('teamDoc.rightBtnList.cancelTop') : this.$t('teamDoc.rightBtnList.top'),
                disabled: this.judgePermission(pageType == 'enterprise' ? 'jurisdiction' : 'update', myFIleRoleList),
                onClick: () => {
                  this.TopMarkClick(this.tableRowArray[0]);
                }
              },
              {
                icon: 'el-icon-document-copy',
                label: this.$t('teamDoc.rightBtnList.copy'),
                hidden: pageType == 'enterprise',
                disabled: this.judgePermission('copy', myFIleRoleList),
                onClick: () => {
                  this.menuCopy();
                }
              },
              {
                icon: 'el-icon-scissors',
                label: this.$t('teamDoc.rightBtnList.move'),
                hidden: pageType == 'enterprise',
                disabled: this.judgePermission('move', myFIleRoleList),
                onClick: () => {
                  this.menuMove();
                }
              },
              {
                icon: 'el-icon-delete',
                label: pageType != 'enterprise' ? this.$t('teamDoc.rightBtnList.delete') : this.$t('teamDoc.rightBtnList.invalid'),
                disabled: this.judgePermission('delete', myFIleRoleList),
                onClick: () => {
                  this.menuDelete();
                }
              },
              {
                icon: 'el-icon-delete',
                label: this.$t('teamDoc.rightBtnList.deleteTemplate'),
                hidden: pageType == 'enterprise' && this.tableRowArray[0].hasOwnProperty('templateName') ? false : true,
                disabled: this.judgePermission('delete', myFIleRoleList),
                onClick: () => {
                  this.delMod();
                }
              },
              {
                icon: 'el-icon-key',
                label: this.$t('teamDoc.rightBtnList.rechristen'),
                divided: true, //是否显示分割线
                disabled: this.judgePermission('update', myFIleRoleList),
                onClick: () => {
                  this.menuRename();
                }
              },
              {
                icon: this.tableRowArray[0].collection == 0 ? 'iconfont icon-collect' : 'iconfont icon-collect-fill',
                label:
                  this.tableRowArray[0].collection == 0 ? this.$t('teamDoc.rightBtnList.collect') : this.$t('teamDoc.rightBtnList.cancelCollect'),
                onClick: () => {
                  this.menuCollect();
                }
              },
              {
                icon: this.tableRowArray[0].attention == 0 ? 'iconfont icon-like' : 'iconfont icon-like-fill',
                label:
                  this.tableRowArray[0].attention == 0
                    ? this.$t('teamDoc.rightBtnList.subscription')
                    : this.$t('teamDoc.rightBtnList.cancelSubscription'),
                hidden: pageType == 'enterprise' || pageType == 'team' ? false : true,
                onClick: () => {
                  this.menuattention();
                }
              },
              {
                icon: 'el-icon-collection',
                label: this.$t('teamDoc.rightBtnList.tags'),
                hidden: pageType != 'self',
                onClick: () => {
                  this.menuLebal();
                }
              },
              {
                icon: 'el-icon-reading',
                label: this.$t('teamDoc.rightBtnList.teamTags'),
                hidden: pageType != 'team',
                disabled: this.judgePermission('label', myFIleRoleList),
                onClick: () => {
                  this.menuTeamLabelClick(this.tableRowArray[0]);
                }
              },
              {
                icon: 'el-icon-receiving',
                label: this.$t('teamDoc.rightBtnList.distribute'),
                hidden: pageType == 'enterprise',
                disabled: this.judgePermission('distribute', myFIleRoleList),
                onClick: () => {
                  this.menuOutEnjoy();
                }
              },
              {
                icon: 'el-icon-share',
                label: this.$t('teamDoc.rightBtnList.share'),
                hidden: pageType == 'enterprise',
                divided: true, //是否显示分割线
                disabled: this.judgePermission('share', myFIleRoleList),
                onClick: () => {
                  this.menuEnjoy(this.tableRowArray[0]);
                }
              },
              {
                icon: 'el-icon-user',
                label: this.$t('teamDoc.rightBtnList.assignPermissions'),
                hidden: pageType == 'self',
                // disabled: this.judgePermission("jurisdiction", myFIleRoleList),
                disabled: this.menuJurisdiction(myFIleRoleList),
                onClick: () => {
                  this.allocating();
                }
              },
              {
                icon: 'el-icon-s-custom',
                label: this.$t('teamDoc.rightBtnList.handOverDocuments'),
                // hidden: pageType == "self",
                hidden: this.isShowOwner(),
                disabled: false,
                onClick: () => {
                  this.updateOwner();
                }
              },
              {
                icon: 'el-icon-wallet',
                label: this.$t('teamDoc.rightBtnList.details'),
                divided: true, //是否显示分割线
                onClick: () => {
                  this.openFileDetailClick(this.tableRowArray[0]);
                }
              },

              {
                icon: 'el-icon-upload2',
                label: '导出',
                hidden: this.tableRowArray[0].type != 'folder',
                divided: true, //是否显示分割线
                onClick: () => {
                  this.exportFun(this.tableRowArray[0]);
                  // this.openFileDetailClick(this.tableRowArray[0]);
                }
              },

              {
                icon: 'el-icon-refresh',
                label: this.$t('teamDoc.rightBtnList.tbdzsk'),
                hidden: this.isSyncKnowledgeFunc(this.tableRowArray),
                divided: true, //是否显示分割线
                onClick: () => {
                  this.synchronizationKnowledge(this.tableRowArray);
                }
              },
              {
                icon: 'el-icon-more-outline',
                label: this.$t('teamDoc.rightBtnList.more'),
                onClick: () => {},
                children: [
                  {
                    icon: 'el-icon-plus',
                    label: this.$t('teamDoc.rightBtnList.commitTeam'),
                    hidden: pageType != 'self',
                    onClick: () => {
                      this.fileSubmitToTeam(this.tableRowArray);
                    }
                  },
                  {
                    icon: 'el-icon-plus',
                    label: this.$t('teamDoc.rightBtnList.submitEnterprise'),
                    hidden: pageType != 'team' && pageType != 'self', //是否隐藏菜单项
                    disabled: this.judgePermission('commitEnterprise', myFIleRoleList),
                    onClick: () => {
                      this.menuEnterRoom();
                    }
                  },
                  {
                    icon: 'el-icon-upload2',
                    label: this.$t('teamDoc.rightBtnList.fileIntoStorage'),
                    hidden:
                      pageType == 'enterprise' && this.$yuUtils.LicenseInfoFunc('archives:list') && this.tableRowArray[0].type != 'folder'
                        ? false
                        : true,
                    disabled: this.judgePermission('toArchives', myFIleRoleList),
                    onClick: () => {
                      this.menuPigeonhole();
                    }
                  },

                  {
                    icon: 'el-icon-circle-plus-outline',
                    label: this.$t('teamDoc.rightBtnList.joinTemplates'),
                    hidden:
                      !(this.tableRowArray[0].type == 'file' && ['ppt', 'excel', 'docx'].indexOf(this.tableRowArray[0].suffix > -1)) ||
                      pageType == 'enterprise',
                    // disabled: this.judgePermission("distribute", myFIleRoleList),
                    onClick: () => {},
                    children: [
                      {
                        label: this.$t('teamDoc.rightBtnList.personalTemplateLibrary'),
                        onClick: () => {
                          this.templateLibrary();
                        }
                      },
                      {
                        label: this.$t('teamDoc.rightBtnList.commonTemplateLibrary'),
                        onClick: () => {
                          this.publicTemplateLibrary();
                        }
                      }
                    ]
                  },

                  {
                    icon: 'el-icon-reading',
                    label: this.$t('teamDoc.rightBtnList.tagDocuments'),
                    hidden: pageType != 'enterprise',
                    disabled: this.judgePermission('enterpriseLabel', myFIleRoleList),
                    onClick: () => {
                      this.menuManyDimensions(this.tableRowArray[0]);
                    }
                  },
                  {
                    icon: 'el-icon-c-scale-to-original',
                    label: this.$t('teamDoc.rightBtnList.fileWatermarking'),
                    hidden: pageType != 'enterprise',
                    disabled: this.judgePermission('watermark', myFIleRoleList),
                    onClick: () => {
                      this.OpenFileWatermark(this.tableRowArray[0]);
                    }
                  },
                  {
                    icon: 'el-icon-data-analysis',
                    label:
                      this.tableRowArray[0].toTms == 'true' ? this.$t('teamDoc.rightBtnList.canceTrain') : this.$t('teamDoc.rightBtnList.joinTrain'),
                    // label: `加入培训资源${this.$store.state.settings.train_enable == 'true'}${pageType != "self"}${this.tableRowArray[0].type == "file"}`,
                    hidden: !(this.$store.state.settings.train_enable == 'true' && pageType != 'self' && this.tableRowArray[0].type == 'file'),
                    disabled: this.judgePermission('jurisdiction', myFIleRoleList),
                    onClick: () => {
                      this.addTrainResourceClick(this.tableRowArray[0]);
                    }
                  },
                  {
                    icon: 'el-icon-sort',
                    label: this.$t('teamDoc.rightBtnList.inOut'),
                    hidden: this.fileFerryHidden(),
                    onClick: () => {
                      this.FileFerryDocuments(this.tableRowArray);
                    }
                  },
                  // {
                  //   icon: "el-icon-folder",
                  //   label: "关联文件",
                  //   hidden: pageType != "enterprise",
                  //   onClick: () => {
                  //     this.menuRelevancy();
                  //   }
                  // },
                  {
                    icon: 'el-icon-link',
                    label: this.$t('teamDoc.rightBtnList.inviteCollaboration'),
                    hidden: pageType != 'self',
                    onClick: () => {
                      this.menuInvitationEdit(this.tableRowArray[0]);
                    }
                  }

                  // {
                  //   icon: "el-icon-refresh-right",
                  //   label: "同步权限", //同步权限至所有下级
                  //   hidden: pageType != "team",
                  //   disabled: this.judgePermission("jurisdiction", myFIleRoleList),
                  //   onClick: () => {
                  //     this.apiTeamRelevanceRoleSyncJuniorPerm(this.tableRowArray[0]);
                  //   }
                  // }
                  // {
                  //   icon: "el-icon-download",
                  //   label: "驱动流程",
                  //   hidden: pageType == "team" && this.tableRowArray[0].type == "file" ? false : true,
                  //   onClick: () => {
                  //     this.startTestFlowClick();
                  //   }
                  // }
                ]
              }

              // {
              //    icon: "el-icon-date",
              //    label: "历史版本",
              //    onClick: () => { this.menuHistory() }
              // },

              // {
              // icon: "el-icon-refresh",
              //    label: "使用网页翻译(T)",
              //    divided: true,
              //    minWidth: 0,
              //    children: [{ label: "翻译成简体中文" }, { label: "翻译成繁体中文" }]
              // },
              // {
              //    label: "截取网页(R)",
              //    minWidth: 0,
              //    children: [
              //       {
              //          label: "截取可视化区域",
              //          onClick: () => {
              //             this.message = "截取可视化区域";
              //             console.log("截取可视化区域");
              //          }
              //       },
              //       { label: "截取全屏" }
              //    ]
              // },
            ],
            event,
            //x: event.clientX,
            //y: event.clientY,
            customClass: 'custom-class', //在app.vue
            zIndex: 9999,
            minWidth: 160
          });
        }
        return false;
      },
      // 打开/预览
      menuPreview() {
        // console.log('预览handleRowDblClick')
        this.handleRowDblClick(this.tableRowArray[0]);
        console.log(this.tableRowArray[0], 'this.tableRowArray[0]');
      },
      // 在线编辑
      menuOnlineEdit() {
        this.tableRowArray[0].type == 'richText' ? this.modifyFormDocument() : this.onlineEditClick(this.tableRowArray[0]);
      },
      // 加入模板库 -- 个人模板库
      templateLibrary() {
        this.uploadModel(this.tableRowArray[0]);
      },
      // 加入模板库 -- 公共模板库
      publicTemplateLibrary() {
        this.addPublicTemplateLibrary(this.tableRowArray[0]);
      },

      // 分发
      menuOutEnjoy() {
        // this.$parent.$refs.docButtonsRefs.openDialogOutEnjoyClick()
        this.openDistribute(this.tableRowArray);
      },
      // 申请文件入库
      menuEnterRoom() {
        console.log('点击提交企业库');
        this.open_yuEnterRoomDialog(this.tableRowArray);
      },
      // 归档入库
      menuPigeonhole() {
        this.open_yuPigeonholeDIalog(this.tableRowArray);
      },
      // 下载
      menuDownload() {
        this.downloadFileFunc(this.tableRowArray[0]);
      },
      // 重命名
      menuRename() {
        this.opendialogRename('rename', this.tableRowArray[0]);
      },
      // 收藏
      menuCollect() {
        this.apiFilesCollectionAddCollection(this.tableRowArray[0]);
      },
      //关注
      menuattention() {
        this.apiFileAttentionAddAttention(this.tableRowArray[0]);
        this.$getNotice.getNoticeNumber();
      },
      // 添加标签
      menuLebal() {
        this.openTagsDialog(this.tableRowArray[0]);
      },
      //团队标签
      menuTeamLabelClick(item) {
        // console.log(row,"row");
        this.$refs.teamTagsRefs.parentObj = item;
        this.$refs.teamTagsRefs.apiFilesLabelRecordQuerySelect(item);
        this.$refs.teamTagsRefs.apiFilesUserLabelQuery();
        this.$refs.teamTagsRefs.personLabelDialog = true;
      },
      //添加多维文档
      menuManyDimensions() {
        this.addManyDimensions();
      },
      // 分享
      async menuEnjoy(row) {
        // this.openEnjoyDialog(this.tableRowArray[0], 'obj')
        // this.treeLoading = true;
        await this.$refs.FileDetailAll.enjoyMoreAndRightClick(row);
        // this.treeLoading = false;
      },
      // 分配权限
      allocating() {
        this.openFilePermClick(this.tableRowArray[0]);
      },
      // 分配权限（权限）
      menuJurisdiction(myFIleRoleList) {
        // console.log(myFIleRoleList, "myFIleRoleList");
        if (this.judgePermission('jurisdiction', myFIleRoleList) == false) {
          return false;
        } else if (this.tableRowArray[0].isInsertPerm == true) {
          return false;
        } else {
          return true;
        }
      },
      isShowOwner() {
        if (
          pageType == 'enterprise' &&
          this.$store.getters['user'].id == this.tableRowArray[0].createId &&
          this.tableRowArray[0].type != 'richText'
        ) {
          return false;
        } else {
          return true;
        }
      },
      // 移交文件夹
      updateOwner() {
        this.updateOwnerClick(this.tableRowArray);
      },
      // 复制
      menuCopy() {
        this.openDocumentTreeAll('copy', this.tableRowArray);
      },
      // 移动
      menuMove() {
        this.openDocumentTreeAll('move', this.tableRowArray);
      },
      // 删除
      menuDelete() {
        this.deleteFileClick(this.tableRowArray);
        // if (pageType != "enterprise") {
        //   this.deleteFileClick(this.tableRowArray);
        // } else {
        //   this.getAbolishFile(this.tableRowArray);
        // }
      },
      // 历史版本
      menuHistory() {
        this.$refs.yuFileDetailRefs.apiOnlineSelectFilesVersions();
      },
      //关联文件
      menuRelevancy() {
        this.$refs.parentRelevanceFile.apiFilesTreeQuery();
        this.$refs.parentRelevanceFile._data.dialogRelevancy = true;
      },
      // 属性
      menuattribute() {
        this.openRightInfoClick();
      },
      //删除模板---yang
      delMod() {
        this.deleteModules();
      },
      //发起测试流程
      startTestFlowClick() {
        this.apiTeamFilesTreeGetFunaction();
      },

      // 表单文档修改（自定义表单） --wen
      modifyFormDocument() {
        this.modifyFormDocumentData(this.tableRowArray[0]);
      },
      // 发起协同编辑
      menuInvitationEdit(row) {
        if (row.type == 'folder' || row.type == 'file') {
          this.$refs.invitationEditRefs.openInvitationEdit(row);
        } else {
          this.$message.warning('请选择文件或文件夹');
        }
      },
      //提交到团队
      fileSubmitToTeam(arr) {
        let ids = arr.map((item) => item.id);
        this.$refs.submitFileToTeamRefs.openSubmitToTeam(ids);
      },

      /**icon转换 */
      selectSvgIcons(v) {
        return this.$yuUtils.selectSvgIcon(v);
      },
      /**table 样式调整 ------------  start */
      // 单元格的 style 的回调方法
      cellStyle({ row, column, rowIndex, columnIndex }) {
        if (columnIndex === 1) {
          return `borderColor:#eee;`;
        } else {
          return `border-right:0px`;
        }
      },

      //表头行的 style 的回调方法
      headerCellStyle({ row, column, rowIndex, columnIndex }) {
        // if (columnIndex === 1) {
        //    return `borderColor:#eee;`;
        // } else {
        //    return "border-right:0px";
        // }
        let base = {
          'background-color': 'rgba(67, 137, 249, 0)',
          color: '#333',
          'text-align': 'left'
        };
        //这里为了是将第一列的表头隐藏，就形成了合并表头的效果
        if (rowIndex === 0 && this.isTableHeaderBtn) {
          // 判断对第几列合并  property就是prop传入的属性
          if (row[columnIndex].property === 'realName') {
            //第一列width扩展2倍
            return { ...base, width: '3000%', display: 'inline-block' };
          } else if (row[columnIndex].property === 'part2') {
            //其余列设置font-size 0 隐藏
            return { 'font-size': 0 };
          }
        } else {
          if (row[columnIndex].property == 'handle') {
            return { ...base, 'text-align': 'center' };
          }
        }
        return base;
      },

      //某一行改变背景色
      tableRowClassName({ row, rowIndex }) {
        if (row.sort == -1) {
          return 'table_row_topmark';
        }
      },
      //排序按钮显示方法
      isTableHeaderBtnFunction() {
        if (this.tableRowArray.length == 0) {
          return 'custom';
        } else {
          return false;
        }
      },
      /**
       *  el-table滚动到表格某一行
       *  @param {object} tableElement  表格元素(this.$refs['表格ref值'])
       *  @param {Object} row   要定位的某一行数据
       * 调用实例   tableScrollToRow(this.$refs.editTable, {})
       */
      tableScrollToRow(tableElement, row) {
        let rowIndex = this.tableData.findIndex((item) => item.id == row.id);
        let rowObj = this.tableData.find((item) => item.id == row.id);
        const theTableRows = tableElement.bodyWrapper.querySelectorAll('.el-table__body tbody .el-table__row');
        let scrollTop = 0;
        for (let i = 0; i < theTableRows.length; i++) {
          if (i === rowIndex) {
            break;
          }
          scrollTop += theTableRows[i].offsetHeight;
        }
        tableElement.bodyWrapper.scrollTop = scrollTop;
        tableElement.setCurrentRow(rowObj);
      },
      // 合并第一行
      arraySpanMethod({ row, column, rowIndex, columnIndex }) {
        if (rowIndex === 0) {
          return {
            rowspan: 1,
            colspan: 5 // 合并全部五列
          };
        }
      },
      /**table 样式调整 ------------  end */

      /**更多 */
      moreHandleCommand(command, item) {
        if (command == 'preview') {
          // 预览
          this.handleRowDblClick(item);
        }
        if (command == 'edit') {
          // 在线编辑
          item.type == 'richText' ? this.modifyFormDocument() : this.onlineEditClick(item);
        }
        if (command == 'outEnjoy') {
          //外发
          this.openDistribute([item]);
        }
        if (command == 'enjoy') {
          //分享
          // this.openEnjoyDialog(item, "obj");
          this.menuEnjoy(item);
        }
        if (command == 'exportBtn') {
          // 导出
          this.exportFun(item);
        }
        if (command == 'move') {
          // 移动
          // this.moveBtnClick("move");
          this.openDocumentTreeAll('move', [item]);
        }
        if (command == 'copy') {
          // 复制
          // this.moveBtnClick("copy");
          this.openDocumentTreeAll('copy', [item]);
        }
        if (command == 'print') {
          // 打印
          this.menuPrintClick(item);
        }
        if (command == 'download') {
          // 下载
          this.downloadFileFunc(item);
        }
        if (command == 'delete') {
          //删除
          this.deleteFileClick([item]);
        }
        if (command == 'rename') {
          // 重命名
          this.opendialogRename('rename', item);
        }
        if (command == 'label') {
          // 标签
          this.openTagsDialog(item);
        }
        if (command == 'labelTeam') {
          //团队标签
          this.menuTeamLabelClick(item);
        }
        // 标签文档
        if (command == 'labelDoc') {
          this.menuManyDimensions(item);
        }
        // 文件水印
        if (command == 'watermark') {
          this.OpenFileWatermark(item);
        }
        // 加入培训资源
        if (command == 'addTrain') {
          this.addTrainResourceClick(item);
        }
        if (command == 'enterRoom') {
          // 申请入库
          this.open_yuEnterRoomDialog([item]);
        }
        // yang
        if (command == 'ferryFile') {
          //内外网摆渡

          this.FileFerryDocuments([item]);
        }
        if (command == 'pigeonhole') {
          // 归档入库
          this.open_yuPigeonholeDIalog([item]);
        }
        if (command == 'visitor') {
          // 分配权限
          this.openFilePermClick(item); //这个方法在docMixins.js页面上
        }
        if (command == 'attention') {
          //关注
          this.apiFileAttentionAddAttention(item);
          this.$getNotice.getNoticeNumber();
        }
        if (command == 'history') {
          //历史版本
          this.$refs.yuFileDetailRefs.apiOnlineSelectFilesVersions();
        }
        if (command == 'testflow') {
          //发起测试流程
          this.apiTeamFilesTreeGetFunaction();
        }
        if (command == 'relevancy') {
          //关联文件
          this.menuRelevancy();
        }
        if (command == 'invitationEdit') {
          // 邀请协同
          this.menuInvitationEdit(item);
        }
        if (command == 'submitFileToTeam') {
          // 提交文件到团队
          this.fileSubmitToTeam([item]);
        }
        // 加入到个人模板库
        if (command == 'templateLibrary') {
          this.tableRowArray = [item];
          this.templateLibrary();
        }
        // 加入公共模板库
        if (command == 'publicTemplateLibrary') {
          this.tableRowArray = [item];
          this.publicTemplateLibrary();
        }
        if (command == 'syncPermission') {
          // 同步文件夹权限至所有下级
          this.apiTeamRelevanceRoleSyncJuniorPerm(item);
        }
        if (command == 'updateOwner') {
          this.tableRowArray = [item];
          this.updateOwnerClick();
        }
      },

      /**下载==================================================start */
      // 单个下载
      async downloadFileFunc(item) {
        if (item.type == 'richText') {
          this.$message.warning('暂不支持下载.richText格式的文件');
          return;
        }
        if (item.type == 'folder') {
          // this.$message.warning("暂不支持下载该格式");
          this.treeLoading = true;
          await this.$YUdowmload.YUdownloadFolder([item]);
          this.treeLoading = false;
        } else {
          this.$YUdowmload.YUdowmloadFiles([item]);
        }
      },
      // 批量下载---表格头下载按钮
      async batchDownloadClick(fileList) {
        if (fileList.findIndex((item) => item.type == 'richText') != -1) {
          this.$message.warning('暂不支持下载.richText格式的文件');
          return;
        }
        if (fileList.length == 1 && fileList.findIndex((item) => item.type == 'file') != -1) {
          //文件下载
          this.$YUdowmload.YUdowmloadFiles(fileList);
        } else {
          try {
            this.treeLoading = true;
            await this.$YUdowmload.YUdownloadFolder(fileList);
            this.treeLoading = false;
          } catch (error) {
            console.log(error);
            this.treeLoading = false;
          }
        }
      },

      /**下载==================================================end */

      /**打开创建文件夹和重名 */
      opendialogRename(type, item) {
        if (type.type != 'richText') {
          let _data = this.$refs.yuCreateFolderRef;

          //重命名
          if (type == 'rename') {
            _data.form = JSON.parse(JSON.stringify(item));
          }
          _data.visibleDialog = true;
        } else {
          // wen
          let params = {
            name: this.docBtnRefsData.form.rename,
            type: 1, // 个人0 团队1
            treeNodeId: this.tableRowArray[0].id,
            id: this.tableRowArray[0].id
          };
          bpmnFromsApi.apiSysFormDocUpdate(JSON.stringify(params)).then((res) => {
            this.docBtnRefsData.dialogRename = false;
            this.userDefinedRefresh('更新成功');
          });
        }
        // console.log(type,"type",item,"item团队文件重命名")
      },
      /**确定事件-创建文件夹和重命名 */
      realNameConfirmClick(item) {
        //重命名
        let params = null;
        if (item.id) {
          if (item.type != 'richText') {
            //文件夹和文件
            if (pageType == 'self') {
              params = {
                folderName: item.realName,
                id: item.id,
                parentId: item.parentId
              };
            } else if (pageType == 'team') {
              params = {
                id: item.id,
                realName: item.realName
              };
            } else if (pageType == 'enterprise') {
              params = {
                id: item.id,
                realName: item.realName
              };
            } else {
              params = {
                parentId: this.propsButtonObj.key || this.headNodeId,
                realName: item.realName
              };
            }
            this.treeLoading = true;
            requstApi
              .apiFilesTreeRename(params)
              .then((res) => {
                if (res.code == '401') {
                  this.$message.error(res.message);
                  return;
                }
                this.refreshDatas();
                this.$message.success('修改成功');
              })
              .catch((err) => {
                this.treeLoading = false;
              });
          } else {
            //表单父文件
            params = {
              name: item.realName,
              type: pageType == 'self' ? 0 : 1, // 个人0 团队1
              treeNodeId: item.id,
              id: item.id
            };
            this.treeLoading = true;
            bpmnFromsApi
              .apiSysFormDocUpdate(JSON.stringify(params))
              .then((res) => {
                this.refreshDatas();
                this.$message.success('修改成功');
              })
              .catch((err) => {
                this.treeLoading = false;
              });
          }
        } else {
          //创建
          if (pageType == 'self') {
            //个人
            params = {
              parentId: this.propsButtonObj.key || this.propsParentId,
              folderName: item.realName
            };
          } else if (pageType == 'team') {
            //团队
            params = {
              parentId: this.propsButtonObj.key || this.headNodeId,
              realName: item.realName,
              teamId: this.teamId
            };
          } else {
            //企业
            params = {
              parentId: this.propsButtonObj.key || this.headNodeId,
              realName: item.realName,
              extend: 1
            };
          }
          this.treeLoading = true;
          requstApi
            .apiFilesTreeAddFolder(params)
            .then((res) => {
              if (res.code == '401') {
                this.$message.error(res.message);
                return;
              }
              if (res.code != '400') {
                this.refreshDatas();
              } else {
                this.$message.error(res.message);
              }
            })
            .catch((err) => {
              this.treeLoading = false;
            });
        }
      },

      /**search-sort组件---排序点击事件 */
      sortListClick(val) {
        let params = {
          sortDesc: 'type,create_time'
        };
        if (val.valueIndex == 0) {
          this.treeRequestParams = params;
        } else {
          this.treeRequestParams = val.value[val.valueIndex - 1];
        }
        this.refreshDatas();
      },
      /**searchSort组件-搜索框事件 */
      inputSearchEnter(val) {
        console.log(val);
      },

      /**复制粘贴移动--打开树弹窗 */
      async openDocumentTreeAll(type, arr) {
        this.treeLoading = true;
        await this.$refs.documentTreeAllRefs.getTreeList();
        this.treeLoading = false;
        this.copyAndMoveType = type;
        this.copyAndMoveArray = arr;
      },

      /**
       * 复制粘贴移动--树弹窗确定按钮
       * 注意:后端处理了:复制移动不能做复制到自己的子目录
       * */
      documentTreeAll_copyMove(val) {
        let ids = this.copyAndMoveArray.map((item) => {
          return item.id;
        });
        this.treeLoading = true;
        if (this.copyAndMoveType == 'move') {
          if (this.copyAndMoveArray[0].parentId == val.id) {
            this.treeLoading = false;
            this.$message.warning('目标目录是原文件当前目录');
            return;
          }
          requstApi
            .apiFilesTreeMove({
              ids: ids,
              parentId: val.id
            })
            .then((res) => {
              this.refreshDatas();
              this.copyAndMoveType = '';
              this.copyAndMoveArray = [];
              if (res.code == '206') {
                this.$message({
                  message: res.message,
                  duration: 5000,
                  type: 'warning',
                  showClose: true
                });
              } else {
                this.$message.success('操作成功');
              }
              this.treeLoading = false;
            })
            .catch((err) => {
              this.treeLoading = false;
            });
        } else {
          requstApi
            .apiFilesTreeCopy({
              ids: ids,
              parentId: val.id
            })
            .then((res) => {
              // this.refreshDatas();
              this.$message.success('操作成功');
              this.copyAndMoveType = '';
              this.copyAndMoveArray = [];
              this.treeLoading = false;
            })
            .catch((err) => {
              this.treeLoading = false;
            });
        }
      },

      /*删除------------------*/
      deleteFileClick(arr) {
        // if (arr[0].libraryType == "enterprise") {
        //   this.getAbolishFile(arr);
        // } else {
        // 如果正在上传中，则无法删除该文件夹
        if (sessionStorage.getItem('isLoading') === 'true') {
          this.$message.warning('文件正在上传中，无法删除！');
          return;
        } else {
          let ids = arr.map((item) => item.id);

          this.$confirm('将删除' + arr.length + '条数据,是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          })
            .then(() => {
              this.treeLoading = true;
              requstApi
                .apiFilesTreeDelete({
                  ids: ids.join(','),
                  type: arr[0].libraryType
                })
                .then((res) => {
                  this.refreshDatas();
                  this.$message.success('删除成功');
                  this.treeLoading = false;
                })
                .catch((err) => {
                  this.treeLoading = false;
                });
            })
            .catch(() => {});
        }

        // }
      },

      // 当选择项发生变化时会触发该事件
      async handleSelectionChange(selection) {
        this.tableRowArray = selection;
        this.tableRowArray.length != 0 ? (this.isTableHeaderBtn = true) : (this.isTableHeaderBtn = false);
        //多个文件判断权限表格头按钮显示
        let paramsString = {};
        if (this.tableRowArray.length >= 1) {
          if (pageType == 'team') {
            paramsString = {
              teamId: this.teamId,
              userId: this.$store.state.user.user.id,
              treeNodeIds: this.tableRowArray.map((item) => item.id)
            };
            this.$store.dispatch('getUserTeamFileRoleApi', {
              params: paramsString
            });
          }
          if (pageType == 'enterprise') {
            // console.log(this.tableRowArray.find(item=>item.perm=='query',123))
            let paramsQuery = this.tableRowArray.find((item) => item.perm == 'query');
            let paramsEditor = this.tableRowArray.find((item) => item.perm == 'editor');
            if (paramsQuery) {
              this.$store.dispatch('getEnteroriseFileRole', {
                params: paramsQuery
              });
            } else if (paramsEditor) {
              this.$store.dispatch('getEnteroriseFileRole', {
                params: paramsEditor
              });
            } else {
              this.$store.dispatch('getEnteroriseFileRole', {
                params: this.tableRowArray[0]
              });
            }
          }
          // } else {
          //    if (pageType == "team") {
          //       // this.propsButtonObj.key || this.headNodeId
          //       // console.log(this.propsButtonObj.key, this.headNodeId);
          //       // if(this.propsButtonObj.key){//这在是文件夹的时候
          //       paramsString.treeNodeIds = [this.propsButtonObj.key || this.headNodeId]
          //       this.$store.dispatch("getUserTeamFileRoleApi", params:paramsString)
          //       // }
          //       // else{//这是在团队根目录
          //       //    this.$store.dispatch("getUserTeamRoleApi", { teamId: this.teamId, userId: this.$store.state.user.user.id });
          //       // }

          //    }
        }
      },

      /** 打开标签对话框 */
      openTagsDialog(item) {
        this.$refs.yuTagsRefs.parentObj = item;
        this.$refs.yuTagsRefs.apiFilesLabelRecordQuerySelect(item);
        this.$refs.yuTagsRefs.apiFilesUserLabelQuery();
        this.$refs.yuTagsRefs.personLabelDialog = true;
      },

      /**刷新表格和数节点 */
      refreshDatas(str) {
        if (pageType == 'self') {
          this.refreshTree();
        } else {
          this.userDefinedRefresh(str);
        }
      },

      // 自定义文档（word,ppt,excel,表单）
      customizeDocument() {
        this.showCustomDocumentDialog();
      },

      /**打开导出文档对话框 */
      async exportFun(item) {
        let data = item;
        if (!item.length) {
          data = [item];
        }
        let res = data.filter((iten) => iten.perm != 'manage');
        if (res.length != 0 && pageType == 'enterprise') {
          this.$message.warning('无权限导出');
          return;
        }
        await this.$refs.ExportInfoRefs.OpenDialog(item, this.stratBreadList, this.breadList);
      },

      /**点击文件获取详情信息 */
      async openFileDetailClick(row) {
        // this.treeLoading = true;
        await this.$refs.FileDetailAll.getDetailInfo(row);
        // this.treeLoading = false;
      },
      /**收藏 */
      //收藏------------------
      apiFilesCollectionAddCollection(row) {
        // let fileType = row.libraryType == "enterprise" ? 2 : 1
        let fileType = '';
        if (row.libraryType == 'enterprise') {
          fileType = 2;
        } else if (row.libraryType == 'team') {
          fileType = 1;
        } else {
          fileType = 0;
        }
        // this.treeLoading = true;
        if (row.collection == '1') {
          requstApi
            .apiFilesCollectionCancelCollection({
              treeNodeId: row.id,
              fileType: fileType
            })
            .then((res) => {
              // this.refreshDatas("取消收藏");
              this.$message.success('取消收藏成功');
              row.collection = '0';
              // this.treeLoading = false
            })
            .catch((err) => {
              // this.treeLoading = false
            });
        } else {
          requstApi
            .apiFilesCollectionAddCollection({
              treeNodeId: row.id,
              fileType: fileType
            })
            .then((res) => {
              // this.refreshDatas("收藏成功了哦~");
              this.$message.success('收藏成功了哦~');
              row.collection = '1';
              // this.treeLoading = false
            })
            .catch((err) => {
              // this.treeLoading = false
            });
        }
      },
      /**权限控制 */
      judgePermission(str, list) {
        if (pageType == 'enterprise') {
          return !this.$yuUtils.documentsPermissionFunc([str], list);
        } else if (pageType == 'team') {
          return !this.$yuUtils.documentsPermissionFunc([str], list);
        } else {
          return false;
        }
      },

      /**breadcrumb-nav create-upload-btn $emit事件 --------start */
      createUploadBtnClick(command) {
        // 新建文件夹
        if (command == 'newFolder') {
          this.opendialogRename('craete');
        }

        //上传文件
        if (command == 'file') {
          if (pageType == 'self') {
            this.openPersonUpload();
          } else if (pageType == 'team') {
            this.open_yuUploadDialog();
          } else if (pageType == 'enterprise') {
            // console.log("企业上传");
            // if (this.breadList.length == 0) {
            //   this.$message.warning("企业文库根目录暂无法上传文件");
            //   return;
            // }
            // this.open_yuUploadDialog();
            // this.openEngUploadDialog();
            this.openPersonUpload();
          }
        }
        // 上传文件流程
        if (command == 'fileProcess') {
          this.openPersonUploadProcess();
        }
        // 上传文件夹流程
        if (command == 'folderProcess') {
          this.openFolderProcess();
        }
        //上传文件夹
        if (command == 'folder') {
          if (pageType == 'enterprise') {
            console.log('企业上传文件夹');
            this.openUploadFolderEN();
          } else {
            this.openUploadFolder();
          }
        }
        // 文件进度弹窗
        if (command == 'fileDialog') {
          this.onFileSelectRequested();
          // console.log('fileDialog')
        }
        if (command == 'folderDialog') {
          this.onTriggerFolder();
          // console.log('folderDialog')
        }
        //
        // 新建自定义文档
        if (command == 'word' || command == 'excel' || command == 'ppt' || command == 'formDocument') {
          // this.showDocumentDialog(command);
          this.showCenterDialog(command);
        }
        // 创建项目
        if (command == 'project') {
          this.openCreateTempProject();
        }
        // 模版中心
        if (command == 'center') {
          this.showCenterDialog(command);
        }
        // 团队模板
        if (command == 'teamTemplate') {
          this.showTeamDialog();
        }
        // if (command == "export") {
        //   this.exportFun(row);
        // }
      },

      // 单击搜索出来的东西
      async handleSelectSearch(row) {
        // this.isSearchMore = false;
        // this.managementList = []
        //  await this.apiFilesTreeQuery();
        this.searchInfoObj = row;
        const fileTypes = {
          self: 'personal',
          team: 'team',
          enterprise: 'enterprise'
        };
        // this.expandedKeys = [];
        // this.$refs.tree2.$data.store.lazy = false
        await collectionApi
          .apiUnifiedCollectionNewGetParentTreeNodeAll({
            id: row.id,
            fileType: fileTypes[pageType],
            sort: this.treeRequestParams.sort,
            size: this.tableRequestParams.size
          })
          .then((res) => {
            let superiorList = [...res.obj.superior];
            superiorList.shift();
            this.expandedKeys = res.obj.superior.map((item) => {
              return parseInt(item.id);
            });
            //设置请求过的数据的高亮,这里为什么有这一步,因为树懒加载请求之后,再次搜索的时候,是不会在走懒加载
            if (pageType == 'self') {
              this.$refs.tree2.setCurrentKey(this.expandedKeys[this.expandedKeys.length - 1]); //设置选中状态
            } else {
              this.$refs.teamTree.setCurrentKey(this.expandedKeys[this.expandedKeys.length - 1]);
            }

            // this.propsParentId = res.obj.tree.id;
            // this.propsButtonObj = {};
            // this.stratBreadList = [];
            // this.breadList = [];
            // this.stratBreadList.push({
            //   id: res.obj.tree.id,
            //   label: res.obj.tree.realName
            // });
            // this.managementList = res.obj.tree.children;

            this.$nextTick(() => {
              // console.log(this.$refs.tree2.$data.store.lazy,'lazy');
              // this.$refs.tree2.$data.store.lazy = true
              /**设置父元素信息 */
              // if (res.obj.superior.length == 1) {
              //   this.propsButtonObj = res.obj.tree.children.length ? res.obj.tree.children[0] : {};
              // } else {
              //   this.propsButtonObj = this.$refs.tree2.getNode(res.obj.superior[res.obj.superior.length - 1])
              // }
              /**设置面包屑路径 */
              // res.obj.superior.forEach(item => {
              //   // console.log(this.$refs.tree2.getNode(parseInt(item)), parseInt(item));
              //   if (this.$refs.tree2.getNode(parseInt(item))) {
              //     this.breadList.push({
              //       id: this.$refs.tree2.getNode(parseInt(item)).key,
              //       label: this.$refs.tree2.getNode(parseInt(item)).label,
              //     })
              //   }
              // })
            });
            // console.log(this.breadList);
            /**设置右边表格数据 */
            if (res.obj.list.page > 1) {
              //判断是否是第一页,顶部加载更多按钮就不显示
              this.isTableTopMoreText = true;
            } else {
              this.isTableTopMoreText = false;
            }
            this.tableData = [];
            if (this.expandedKeys.length == 1) {
              this.breadList = [];
            } else {
              this.breadList = superiorList;
            }
            this.toploadMorePage = res.obj.list.page - 1;
            this.tableRequestParams.page = res.obj.list.page - 1;
            this.tableRequestParams.pageCount = res.obj.list.page; //这里为什么这样写:因为初始在请求列表中判断了页数和总页数,页数要比总页数小才能发送请求
            this.tableRequestParams.parentId = this.expandedKeys[this.expandedKeys.length - 1];
            // console.log(this.tableRequestParams);
            this.apiTreeFileSelectTreePage();
          })
          .catch((err) => {
            console.log(err);
          });

        // collectionApi
        //   .apiUnifiedCollectionGetParentTreeNodeAll({
        //     fileType: fileTypes[pageType],
        //     id: item.id
        //   })
        //   .then((res) => {
        //     // this.isSearchMore = true;
        //     let expandedKeys = res.obj.map((item) => {
        //       return parseInt(item.id);
        //     });
        //     // if(item.type!=='folder'){
        //     // console.log(expandedKeys);

        //     expandedKeys = expandedKeys.slice(0, -1);
        //     // }
        //     if (expandedKeys.length == 0) {
        //       this.getDatas();
        //     } else {
        //       this.$nextTick(() => {
        //         this.expandedKeys = expandedKeys;
        //       });
        //     }
        //   });
      },

      //回到根目录
      pageTitleClick() {
        this.breadRouterClick(this.stratBreadList[0]);
      },

      // 设置右边表格数据
      createUploadBtn_setSearchTableList(val) {
        this.tableData = val;
        // console.log(this.tableData);
        this.searchTableDataClone = this.tableData; //拷贝了一份，用来还原取消搜索时的表格数据
      },
      /**breadcrumb-nav $emit事件 ---------end */

      /**table-header-btn $emit事件 --------start */
      tableHeaderBtn_otherClick(str) {
        if (str == 'label') {
          //标签
          if (this.tableRowArray.length != 1) {
            this.$refs.yuTagsRefs.parentObjs = this.tableRowArray;
            this.$refs.yuTagsRefs.apiFilesUserLabelQuery();
            this.$refs.yuTagsRefs.personLabelDialog = true;
            // this.$message.warning("暂不支持多个文件进行添加标签");
            return;
          }
          this.openTagsDialog(this.tableRowArray[0]);
        }
        if (str == 'collection') {
          // 收藏
          this.apiFilesCollectionAddCollection(this.tableRowArray[0]);
        }
        if (str == 'detail') {
          //详情或者版本
          if (this.tableRowArray.length != 1) {
            this.$message.warning('暂不支持多个文件进行查看详情');
            return;
          }
          this.openFileDetailClick(this.tableRowArray[0]);
        }
        if (str == 'copy') {
          // 复制
          if (this.tableRowArray.length == 0) {
            this.$message.warning('请选择一个或多个文件进行操作');
            return;
          }
          this.openDocumentTreeAll('copy', this.tableRowArray);
        }
        if (str == 'outEnjoy') {
          // 分发
          this.openDistribute(this.tableRowArray);
        }
        if (str == 'syncKnowledge') {
          this.synchronizationKnowledge(this.tableRowArray);
        }
        if (str == 'submitFileToTeam') {
          console.log(this.tableRowArray.length, '123');
          // 提交到团队
          if (this.tableRowArray.length === 1) {
            this.fileSubmitToTeam(this.tableRowArray);
          } else {
            this.$message.warning('请选择一个文件或文件夹进行操作');
          }
        }
        if (str == 'ferryFile') {
          // 内外摆渡
          if (this.tableRowArray.length === 1) {
            this.FileFerryDocuments(this.tableRowArray);
          } else {
            this.$message.warning('请选择一个文件或文件夹进行操作');
          }
        }
        if (str == 'teamLabel') {
          this.$refs.teamTagsRefs.parentObjs = this.tableRowArray;
          this.$refs.teamTagsRefs.apiFilesUserLabelQuery();
          this.$refs.teamTagsRefs.personLabelDialog = true;
        }
        if (str == 'enterpriseLabel') {
          // this.menuManyDimensionsList(this.tableRowArray);

          if (this.tableRowArray.length === 1) {
            this.open_yuEnterRoomDialog(this.tableRowArray);
          } else {
            this.$message.warning('请选择一个文件或文件夹进行操作');
          }
        }
        if (str == 'fileLibrary') {
          this.menuPigeonhole();
        }
        if (str == 'invitationEdit') {
          if (this.tableRowArray.length === 1) {
            this.menuInvitationEdit(this.tableRowArray[0]);
          } else {
            this.$message.warning('请选择一个文件或文件夹进行操作');
          }
        }

        // 加入模板 --个人模板库
        if (str == 'templateLibrary') {
          this.templateLibrary();
        }
        // 加入模板 --公共模板库
        if (str == 'publicTemplateLibrary') {
          this.publicTemplateLibrary();
        }
        // 加入培训
        if (str == 'addTrain') {
          if (this.tableRowArray.length === 1) {
            this.addTrainResourceClick(this.tableRowArray[0]);
          } else {
            this.$message.warning('请选择一个文件或文件夹进行操作');
          }
        }
        if (str == 'exportBtn') {
          //导出
          // if (this.tableRowArray[0].type != "folder") {
          //   this.$message.warning("暂不支持文件导出!");
          //   return;
          // }

          this.exportFun(this.tableRowArray);
        }
      },

      /**table-header-btn $emit事件 --------start */

      // 排序
      changeTableSort(column, prop, order) {
        let freeGood = [];
        let elseFree = [];
        let fieldName = column.prop;
        let sortingType = column.order === 'ascending' ? 'Asc' : column.order === 'descending' ? 'Desc' : null;

        if (fieldName === 'realName') {
          fieldName = 'real_name';
        }
        if (fieldName === 'updateTime') {
          fieldName = 'update_time';
        }
        if (sortingType === null) {
          fieldName = 'create_time';
          sortingType = 'Desc'; // 可以指定默认的排序方式，例如降序
        }

        this.tableData.forEach((item) => {
          if (item.sort == -1) {
            freeGood.push(item);
          } else {
            elseFree.push(item);
          }
        });

        // 根据排序类型进行排序
        if (sortingType === 'Desc' || sortingType === 'Asc') {
          elseFree.sort((a, b) => {
            if (typeof a[fieldName] === 'string') {
              return sortingType === 'Desc' ? b[fieldName].localeCompare(a[fieldName]) : a[fieldName].localeCompare(b[fieldName]);
            } else if (typeof a[fieldName] === 'number') {
              return sortingType === 'Desc' ? b[fieldName] - a[fieldName] : a[fieldName] - b[fieldName];
            }
          });
        }

        // 合并不参与排序的数据和排序后的数据
        this.tableData = [...freeGood, ...elseFree];

        // 更新 treeRequestParams.sort 数组的最后一个参数
        if (sortingType) {
          this.treeRequestParams.sort.pop(); // 移除最后一个元素
          this.treeRequestParams.sort.push(`${fieldName} ${sortingType}`);
        } else {
          // 如果没有排序方式，则还原排序参数
          this.treeRequestParams.sort = ['sort Asc', 'type Desc', 'update_time Asc'];
        }
        this.$emit('sort-changed');
        // 更新管理列表
        let folderData = this.tableData.filter((item) => item.type === 'folder');
        console.log(folderData, 'folderData');
      },
      /**置顶----start */
      TopMarkClick(item) {
        let params = {};
        requstApi
          .apiTreeFileTop({
            ids: [item.id],
            top: item.sort == -1 ? false : true
          })
          .then((res) => {
            this.refreshDatas();
          });
      },
      /**置顶----end */
      /**同步到知识库-----start */
      //是否显示同步知识库按钮 return true为不显示
      isSyncKnowledgeFunc(arr) {
        if (this.$store.state.settings.knowledge_base_state != '0') {
          let knowledge_base_type = this.$store.state.settings.knowledge_base_type ? this.$store.state.settings.knowledge_base_type.split(',') : [];
          let isEverySuffixInArr = arr.every((item) => knowledge_base_type.includes(item.suffix));
          if (pageType == 'enterprise') {
            return arr.some((item) => item.type === 'folder') || !isEverySuffixInArr;
          } else {
            return true;
          }
        } else {
          return true;
        }
      },
      //同步到知识库
      synchronizationKnowledge(arr) {
        if (arr.findIndex((item) => item.type == 'folder') != -1) {
          this.$message.warning('文件夹暂不支持同步到知识库');
          return;
        }
        let knowledge_base_type = this.$store.state.settings.knowledge_base_type.split(',');
        let isEverySuffixInArr = arr.every((item) => knowledge_base_type.includes(item.suffix));
        if (!isEverySuffixInArr) {
          this.$message.warning(`文件类型不支持同步到知识库,目前支持[${knowledge_base_type}]的后缀,请联系管理员修改!`);
          return;
        }
        let ids = arr.map((item) => item.id);
        if (pageType == 'enterprise') {
          requstApi
            .apiEnterpriseFilesTreeSynchronizationKnowledge(ids)
            .then((res) => {
              this.$message.success(this.$t('commen.success'));
            })
            .catch((err) => {
              this.$message.error(this.$t('commen.error'));
            });
        }
      },
      /**同步到知识库-----end */
      /**同步权限至所有下级 */
      apiTeamRelevanceRoleSyncJuniorPerm(row) {
        if (row.type == 'folder') {
          requstApi
            .apiTeamRelevanceRoleSyncJuniorPerm({
              treeNodeId: row.id
            })
            .then((res) => {
              this.refreshDatas();
              this.$message.success(this.$t('commen.success'));
            });
        } else {
          this.$message.warning('暂不支持文件同步权限');
        }
      },
      //**设置文件水印------start */
      OpenFileWatermark(row) {
        this.$refs.yuFileWatermarkRefs.openFileWatermark(row);
      },
      //确定按钮刷新
      confirmWatermarkClick() {
        this.refreshDatas();
      },
      /**设置文件水印------end */

      //打印
      async menuPrintClick(row) {
        let params = {
          id: row.id,
          type: pageType == 'self' ? 'personal' : pageType
        };
        let res = await apiOnlinePrint(params);
        const blobData = [res];
        const blob = new Blob(blobData, { type: 'application/pdf' });
        const blobURL = window.URL.createObjectURL(blob);
        printJS({
          type: 'pdf',
          printable: blobURL,
          documentTitle: '111', //标题
          targetStyle: '*',
          targetStyles: '*',
          scanStyles: true,
          // 默认800，设置1000是因为我窗口宽度是1000，而导致页面靠近左边，设置1000就正常居中了。
          maxWidth: '1300',
          // onPrintDialogClose:()=>{
          //     console.log(111111111111111);
          // },
          // onPdfOpen: ()=>{
          //   console.log(2222222222222222);
          // },
          onLoadingEnd: async () => {
            let params = {
              id: row.id,
              type: pageType == 'self' ? 'personal' : pageType
            };
            let res = await collectionApi.apiOnlinePrintCallBack(params);
          }
          // onLoadingStart: function(){
          //   console.log(4444444444);
          // }
        });
      },
      /**加入培训资源模块----start */
      // 加入培训资源
      addTrainResourceClick(row) {
        if (row.toTms == 'true') {
          // 取消培训资源
          requstApi
            .apiFilesTreeCancelTMS({
              id: row.id
            })
            .then((res) => {
              this.$message.success(this.$t('commen.success'));
              this.refreshDatas();
            })
            .catch((err) => {
              this.$message.error(this.$t('commen.error'));
            });
        } else {
          // 加入培训资源
          requstApi
            .apiFilesTreeJoinTMS({
              id: row.id
            })
            .then((res) => {
              this.$message.success(this.$t('commen.success'));
              this.refreshDatas();
            })
            .catch((err) => {
              this.$message.error(this.$t('commen.error'));
            });
        }
      },
      /**加入培训资源模块----end */
      /*分发同事===========*/
      openDistribute(arr) {
        this.$refs.yuDistributeRefs.openDistributeYu(arr);
      },
      /**内外网摆渡文件----start */
      // 按钮显示判断
      fileFerryHidden() {
        if (this.$store.state.user.ferrySwitch && pageType == 'self' && this.$yuUtils.vifpermissionRoles(['admin', 'ferry:list'])) {
          return false;
        } else {
          return true;
        }
      },
      //内外摆渡
      FileFerryDocuments(arr) {
        this.ferryRequestParams.fileIds = arr.map((item) => item.id);
        this.$refs.yuSelectUserNewUiRefs._data.dialogTransfer = true;
        // let data = this.$refs.yangFerryFile._data;
        // this.$refs.yangFerryFile.getQueryLocation();
        // data.dialogFerryUpload = true;
      },
      // 内外摆渡选人组件确定$emit事件
      sureDialogTransferClick_ferry(val) {
        this.ferryRequestParams.userIds = val.map((item) => item.id);
        requstApi.apiFerryFileFerryDocuments(this.ferryRequestParams).then((res) => {
          if (res.code == '200') {
            // console.log('操作成功');
            this.$message.success(this.$t('commen.success'));
            Object.keys(this.ferryRequestParams).forEach((key) => (this.ferryRequestParams[key] = []));
          } else {
            this.$message.error(res.message);
          }
        });
      }
      /**内外网摆渡文件--------------end */
    }
  };
};
